<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>登录</title>

    <link rel="shortcut icon" href="${ctxPath}/favicon.ico?v=${app.version}">
    <link href="${ctxPath}/assets/plugins/font-awesome/css/font-awesome.min.css?v=4.7.0" rel="stylesheet">
    <link href="${ctxPath}/assets/plugins/bootstrap/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxPath}/assets/common/css/login.css?v=${app.version}" rel="stylesheet">
    <script>if (window.top !== window.self) {
        window.top.location = window.location;
    }</script>
    <script src="${ctxPath}/assets/plugins/jquery/jquery.min.js?v=2.1.4"></script>
    <script src="${ctxPath}/assets/plugins/jquery/jquery.cookie.min.js?v=1.4.1"></script>
    <script src="${ctxPath}/assets/plugins/bootstrap/bootstrap.min.js?v=3.3.6"></script>
    <script src="${ctxPath}/assets/common/js/dawn.js?v=${app.version}"></script>
    <script src="${ctxPath}/assets/common/js/ajax-object.js?v=${app.version}"></script>
</head>

<body class="gray-bg">
<div class="middle-box text-center loginscreen">
    <div style="margin-top: 100px;">
        <h2>欢迎使用 ${app.name}</h2>
        <br/>
        <h4 style="color: red;">${tips!}</h4>
        <div class="m-t" role="form" action="${ctxPath}/login" method="post">
            <div class="form-group">
                <input type="text" name="username" class="form-control" placeholder="用户名" required="">
            </div>
            <div class="form-group">
                <input type="password" name="password" class="form-control" placeholder="密码" required="">
            </div>
            <div class="form-group" style="float: left;">
                <div class="checkbox" style="text-align: left">
                    <label>
                        <input type="checkbox" name="remember" style="margin-top: 2px;">记住我
                    </label>
                </div>
            </div>
            <button type="submit" id="login" class="btn btn-primary block full-width m-b">登 录</button>
            </p>
        </div>
    </div>
</div>
<script>
    var token = localStorage.getItem("Authorization");
    if(typeof token != 'undefined' && token!=null && token != "") {
        $.cookie("Authorization", token);
        $.cookie("account", localStorage.getItem("account"));
        window.location.href = "${ctxPath}/"
    }
    $("#login").click(function (){
        $request.postJson("/login", function (res) {
            if (res.success) {
                $.cookie("Authorization", res.data.token);
                $.cookie("account", $("input[name='username']").val());
                if($("input[name='remember']").is(':checked')) {
                    localStorage.setItem("Authorization", res.data.token);
                    localStorage.setItem("account", $("input[name='username']").val());
                }
                window.location.href = "${ctxPath}/"
            } else {
                Dawn.error(res.message);
            }
        }, function (rdata) {
            Dawn.error(rdata.responseJSON.message);
        }).setData({
            password: $("input[name='password']").val(),
            username: $("input[name='username']").val()
        }).start();
    })
</script>

</body>

</html>
